<?php

namespace app\common\model\Product\Order;

use think\Model;
use traits\model\SoftDelete;

class Order extends Model
{
    protected $name = 'order';

    protected $autoWriteTimestamp = true;

    protected $createTime = 'createtime';

    protected $updateTime = false;
    use SoftDelete;
    protected $deleteTime = 'deletetime';
    protected $append = [
        'status_text', // 订单状态

    ];
    public function getStatusTextAttr($value, $data)
    {
        $status = $data['status'];

        switch ($status) {
            case '0':
                return '待支付';
            case '1':
                return '待发货';
            case '2':
                return '待收货';
            case '3':
                return '待评价';
            case '4':
                return '已完结';
            case '-1':
                return '仅退款';
            case '-2':
                return '退款退货';
            case '-3':
                return '待退货';
            case '-4':
                return '退货成功';
            case '-5':
                return '退货失败';
        }
    }
    public function expressquery()
    {
        return $this->belongsTo('app\admin\model\Expressquery', 'expressid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function business()
    {
        return $this->belongsTo('app\common\model\Business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function region()
    {
        return $this->belongsTo('app\common\model\Region\Region', 'district', 'code', [], 'LEFT')->setEagerlyType(0);
    }
    // 销售员
    public function sale()
    {
        return $this->belongsTo('app\common\model\Admin', 'adminid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    // 发货员
    public function dispatched()
    {
        return $this->belongsTo('app\common\model\Admin', 'shipmanid', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    // 审核员
    public function review()
    {
        return $this->belongsTo('app\common\model\Admin', 'checkmanid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
